package com.parking.mgr.useraccount;

import cn.hutool.core.net.NetUtil;
import com.parking.mgr.useraccount.properties.CosProperties;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * @ClassName BaseServiceApplication
 * @Description SpringBoot方式启动类
 * @Auther: zhijianpu
 * @Date: 2023/5/19
 */
@SpringBootApplication(scanBasePackages = {"com.parking.mgr"})
@EnableConfigurationProperties(CosProperties.class)
@EnableAsync
@Log4j2
public class UseraccountServiceApplication {

    public static void main(String[] args) {
        String applicationName = UseraccountServiceApplication.class.getSimpleName();
        ConfigurableApplicationContext application = SpringApplication.run(UseraccountServiceApplication.class, args);
        final Environment env = application.getEnvironment();
        final String port = env.getProperty("server.port");
        final String contextPath = env.getProperty("server.servlet.context-path", "");
        final String ip = NetUtil.getLocalhost().getHostAddress();

        String[] beanNames = application.getBeanDefinitionNames();
        log.info("bean总数:{}", application.getBeanDefinitionCount());
//        int i = 0;
//        for (String str : beanNames) {
//            logger.info("{},beanName:{}", ++i, str);
//        }


        log.info("\n----------------------------------------------------------" +
                "\n\t " + applicationName + " start success! " +
                "\n\t Access URLs:" +
                "\n\t Local:      [ http://localhost:" + port + contextPath + " ]" +
                "\n\t External:   [ http://" + ip + ":" + port + contextPath + " ]" +
                "\n\t SwaggerDoc: [ http://" + ip + ":" + port + contextPath + "/doc.html ]" +
                "\n----------------------------------------------------------");
    }

    @Bean
    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers(connector -> connector.setProperty("relaxedQueryChars", "|{}[]"));
        return factory;
    }

    /**
     * 注册自定义的LocaleResolver
     */
//    @Bean
//    public LocaleResolver localeResolver(){
//        return new MyLocaleResolver();
//    }

}
